﻿using MyDay13.Context;
using MyDay13.IRepostitype;
using MyDay13.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyDay13Repostitype
{
    public class RoleRepostitype : IRoleRepostitype
    {
        Day13Context db;
        public RoleRepostitype(Day13Context dbs)
        {
            db = dbs;
        }
        public int RoleAdd(D13Role d13Role)
        {
            db.D13Role.Add(d13Role);
            return db.SaveChanges();
        }

        public int RoleDel(string ids)
        {
            var list = db.D13Role.ToList().Where(x => ids.Contains(x.RId.ToString())).ToList();
            db.D13Role.RemoveRange(list);
            return db.SaveChanges();
        }

        public List<D13Role> RoleShow()
        {
            var list = db.D13Role.ToList();
            return list;
        }

        public int RoleUpt(D13Role d13Role)
        {
            db.Entry(d13Role).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return db.SaveChanges();
        }

        public int RPDel(int ids)
        {
            db.Remove(db.D13RolePowerTable.ToList().Where(x => x.RPId == ids).FirstOrDefault());
            return db.SaveChanges();
        }

        public List<D13RolePowerTable> RPManyID(int rid)
        {
            var list = db.D13RolePowerTable.Where(x => x.RoleId == rid).ToList();
            return list;
        }
    }
}
